# def decodeString(s):
#     def decode(i):
#         # 给变了赋值
#         res = ""
#         num = 0
#         # while 循环
#         while i < len(s):
#             if s[i].isdigit():
#                 num = num * 10 + int(s[i])
#
#             elif s[i] == '[':
#                 i, tmp = decode(i + 1)
#                 res = res + num * tmp
#                 num = 0
#             elif s[i] == ']':
#                 return i, res
#
#             else:
#                 res = res + s[i]
#             # 条件控制语句
#             i += 1
#         # 返回值最终变量（或者是输出结果）
#         return i, res
#     return decode(0)[1]
#
# print(decodeString('3[ab]2[cd]'))




# def decodeString(s):
#     def decode(i):
#         # 给变了赋值
#         res = ""
#         num = 0
#         # while 循环
#         while i < len(s):
#             if "0" <= s[i] <= "9":
#                 num = num * 10 + int(s[i])
#
#             elif s[i] == '[':
#                 i, tmp = decode(i + 1)
#                 res = res + num * tmp
#                 num = 0
#             elif s[i] == ']':
#                 return i, res
#
#             else:
#                 res = res + s[i]
#             # 条件控制语句
#             i += 1
#         # 返回值最终变量（或者是输出结果）
#         return i, res
#     return decode(0)
#
# print(decodeString('3[aa]2[cd]'))




def decode_string(s):
    def helper(s, index):
        result = ''
        while index < len(s):
            if s[index].isdigit():
                num = 0
                while index < len(s) and s[index].isdigit():
                    num = num * 10 + int(s[index])
                    index += 1
                if s[index] == '[':
                    index += 1
                    nested_string, index = helper(s, index)
                    result += nested_string * num
                else:
                    return result, index
            else:
                if s[index] == ']':
                    index += 1
                    return result, index
                else:
                    result += s[index]
                index += 1
        return result, index

    return helper(s, 0)[0]

if __name__ == "__main__":
    input_str = input("请输入字符串：")
    decoded_str = decode_string(input_str)
    print("字符串结果为：", decoded_str)










